home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group95b.txt / 000017_icon-group-sender _Thu May 18 15:41:59 1995.msg < prev    next >
Internet Message Format  |  1995-09-18  |  65KB

  1. Received: by cheltenham.cs.arizona.edu; Thu, 18 May 1995 12:20:58 MST
  2. To: icon-group-l@cs.arizona.edu
  3. Date: Thu, 18 May 1995 15:41:59 GMT
  4. From: goer@quads.uchicago.edu (Richard L. Goerwitz)
  5. Message-Id: <D8s69z.KMw@midway.uchicago.edu>
  6. Organization: The University of Chicago
  7. Sender: icon-group-request@cs.arizona.edu
  8. Reply-To: goer@midway.uchicago.edu
  9. Subject: hilit19 + icon revisited
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12. Those of you who are using hilit19.el with GNU Emacs 19 may want to
  13. try out the following code.  What it does is to get string literals
  14. right.  It also allows you to insert a backslash to avoid problems
  15. like pound signs inside of string/cset literals being taken as com-
  16. ment delimiters:
  17.  
  18.     '!@#$%^&*()'
  19.        ^
  20. You just insert a backslash, and everything works fine.  For Icon,
  21. \# and # are equivalent inside a string/cset literal.
  22.  
  23.     '!@\#$%^&*()'
  24.        ^
  25. Has anyone, BTW, actually used the new Icon mode I posted some months
  26. back?  I just couldn't handle all comments being jammed against the
  27. margin, the way the standard Emacs Icon mode has them.
  28.  
  29.  
  30. ;; hilit19.el (Release 2.19) -- customizable highlighting for Emacs19.
  31. ;; Copyright (c) 1993 Free Software Foundation, Inc.
  32. ;; Hacked by Richard Goerwitz, 18 May 1995
  33. ;;
  34. ;; Author:   Jonathan Stigelman <Stig@netcom.com>
  35. ;; Keywords: faces
  36. ;; 
  37. ;; This program is free software; you can redistribute it and/or modify
  38. ;; it under the terms of the GNU General Public License as published by
  39. ;; the Free Software Foundation; either version 2 of the License, or
  40. ;; (at your option) any later version.
  41. ;; 
  42. ;; This program is distributed in the hope that it will be useful,
  43. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  44. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  45. ;; GNU General Public License for more details.
  46. ;; 
  47. ;; You should have received a copy of the GNU General Public License
  48. ;; along with this program; if not, write to the Free Software
  49. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  50. ;;
  51.  
  52. ;;; Commentary:
  53.  
  54. ;; Hilit19.el is a customizable highlighting package for Emacs19.  It supports
  55. ;; not only source code highlighting, but also Info, RMAIL, VM, gnus...
  56. ;; Hilit19 knows (or thinks it knows) how to highlight emacs buffers in
  57. ;; about 25 different modes.
  58. ;; 
  59. ;; WHERE TO GET THE LATEST VERSIONS OF HILIT19.EL (beta and release), 
  60. ;; PLUS LOTS OF OTHER *WAY COOL* STUFF VIA ANONYMOUS FTP:
  61. ;;
  62. ;;      netcom.com:/pub/stig/src/{Beta,Release}/hilit19.el.gz
  63. ;;
  64. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  65. ;;
  66. ;; TO SUBMIT BUG REPORTS (or feedback of any sort)...
  67. ;;
  68. ;;    M-x hilit-submit-feedback RET
  69. ;;
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71. ;;
  72. ;; hilit19.el,v 2.19 1993/09/08 18:44:10 stig Release
  73. ;;
  74. ;; LCD Archive Entry:
  75. ;; hilit19|Jonathan Stigelman|Stig@netcom.com|
  76. ;; Comprehensive (and comparatively fast) regex-based highlighting for Emacs 19|
  77. ;; 1993/09/08 18:44:10|Release 2.19|~/packages/hilit19.el.Z|
  78. ;;
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. ;;
  81. ;; GENERAL OVERVIEW
  82. ;;
  83. ;;      This package installs numerous hooks to colorfully highlight your
  84. ;;      source code buffers as well as mail and news buffers.  Most 
  85. ;;      programming languages have predefined highlighting patterns.
  86. ;;    Just load hilit19 and files will be automatically highlighted as
  87. ;;      they're loaded.
  88. ;;
  89. ;;      Rehighlight a buffer by typing C-S-l (control-shift-lowercase-L).
  90. ;;
  91. ;;      If, when you edit the buffer, the coloring gets messed up, just
  92. ;;      redraw and the coloring will be adjusted.  If automatic highlighting
  93. ;;      in the current buffer has been turned off, then typing C-u C-S-l will
  94. ;;    force a rehighlight of the entire buffer.
  95. ;;
  96. ;;      Hilit19 can build faces by examining the names that you give to them
  97. ;;    For example, green/black-bold-italic-underline would be created as
  98. ;;    a face with a green foreground, and a black background, using a 
  99. ;;    bold-italic font...with underlining for good measure.
  100. ;;
  101. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  102. ;;
  103. ;; SETUP -- In your .emacs:
  104. ;;
  105. ;; 
  106. ;; (cond (window-system
  107. ;;        (setq hilit-mode-enable-list  '(not text-mode)
  108. ;;              hilit-background-mode   'light
  109. ;;              hilit-inhibit-hooks     nil
  110. ;;              hilit-inhibit-rebinding nil)
  111. ;; 
  112. ;;        (require 'hilit19)
  113. ;;        ))
  114. ;; 
  115. ;; If you like font-lock-mode and want to use both packages, then you can
  116. ;; disable hilit for the modes in which you want to use font-lock by listing
  117. ;; said modes in hilit-mode-enable-list.
  118. ;; 
  119. ;;      (hilit-translate type     'RoyalBlue   ; enable highlighting in C/C++
  120. ;;             string      nil)         ; disable string highlighting
  121. ;;
  122. ;; To get 100% of the utility of hilit19, you may also have to apply the
  123. ;; patches below for info.el and vm5.33L_19/vm-summary.el
  124. ;;
  125. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  126. ;;
  127. ;; SETUP -- Are you using the right font for Emacs?
  128. ;;
  129. ;; Emacs cannot properly find bold and italic fonts unless you specify a
  130. ;; verbose X11 font name.  If you specify a font for emacs in your
  131. ;; .Xdefaults, it *MUST* be specified using the long form of the font name.
  132. ;; Here's a good font menu:
  133. ;;
  134. ;; (setq
  135. ;;  x-fixed-font-alist
  136. ;;  '("Font Menu"
  137. ;;    ("Misc"
  138. ;;     ("6x12" "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-*-1")
  139. ;;     ("6x13" "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-1")
  140. ;;     ("lucida 13"
  141. ;;      "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-0-0-m-0-*-1")
  142. ;;     ("7x13" "-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-1")
  143. ;;     ("7x14" "-misc-fixed-medium-r-normal--14-130-75-75-c-70-*-1")
  144. ;;     ("9x15" "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1")
  145. ;;     ("")
  146. ;;     ("clean 8x8" "-schumacher-clean-medium-r-normal--*-80-*-*-c-*-*-1")
  147. ;;     ("clean 8x14" "-schumacher-clean-medium-r-normal--*-140-*-*-c-*-*-1")
  148. ;;     ("clean 8x10" "-schumacher-clean-medium-r-normal--*-100-*-*-c-*-*-1")
  149. ;;     ("clean 8x16" "-schumacher-clean-medium-r-normal--*-160-*-*-c-*-*-1")
  150. ;;     ("")
  151. ;;     ("sony 8x16" "-sony-fixed-medium-r-normal--16-120-100-100-c-80-*-1")
  152. ;;     ("")
  153. ;;     ("-- Courier --")
  154. ;;     ("Courier 10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-*-1")
  155. ;;     ("Courier 12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-*-1")
  156. ;;     ("Courier 14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-*-1")
  157. ;;     ("Courier 18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-*-1")
  158. ;;     ("Courier 18-b" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-*-1")
  159. ;;     )))
  160. ;;
  161. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  162. ;;
  163. ;; KNOWN BUGS/TO DO LIST/HELP WANTED/APPLY WITHIN
  164. ;;
  165. ;; * When more than one size of font is used in different frames, only one
  166. ;;   font size can have bold & italic properties.
  167. ;;
  168. ;; * unbalanced, unescaped double quote characters can confuse hilit19.
  169. ;;   This will be fixed someday, so don't bug me about it.
  170. ;;
  171. ;; * ALTHOUGH HILIT19 IS FASTER THAN FONT-LOCK-MODE...
  172. ;;   For various reasons, the speed of the package could still stand to be
  173. ;;   improved.  If you care to do a little profiling and make things tighter...
  174. ;;
  175. ;; * hilit-toggle-highlight is flaky when auto-rehighlight is neither t nor nil.
  176. ;;   Does anyone actually USE this?  I think I might just remove it.
  177. ;;
  178. ;; PROJECTS THAT YOU CAN TAKE OVER BECAUSE I DON'T MUCH CARE ABOUT THEM...
  179. ;;
  180. ;; * Moved hilit-wysiwyg-replace here from my version of man.el, this is not
  181. ;;   a bug.  The bug is that I don't have a reverse operation yet...just a
  182. ;;   stub Wysiwyg-anything really belongs in a package of it's own.
  183. ;;
  184. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  185. ;;
  186. ;; Thanks to the following people for their input:
  187. ;;    ebert@enpc.enpc.fr (Rolf EBERT), ada, LaTeX & bibtex highlights
  188. ;;    Vivek Khera <khera@cs.duke.edu>, gnus hooks + random advice & patches
  189. ;;    brian@athe.WUstl.EDU (Brian Dunford-Shore), prolog highlights
  190. ;;    John Ladwig <jladwig@soils.umn.edu>, 1st pass nroff highlights
  191. ;;    campo@sunthpi3.difi.unipi.it (Massimo Campostrini), fortran highlights
  192. ;;    jayb@laplace.MATH.ColoState.EDU (Jay Bourland), 1st pass dired
  193. ;;    Yoshio Turner <yoshio@CS.UCLA.EDU>, modula 2 highlights
  194. ;;    Fritz Knabe <knabe@ecrc.de>, advice & patches
  195. ;;    Alon Albert <alon@milcse.rtsg.mot.com>, advice & patches
  196. ;;    dana@thumper.bellcore.com (Dana A. Chee), working on the multi-frame bug
  197. ;;    derway@ndc.com (Don Erway), for breaking it...
  198. ;;    moss_r@summer.chem.su.oz.au (Richard Moss), first pass at add-pattern
  199. ;;    Olivier Lecarme <ol@aiguemarine.unice.fr>, Pascal & Icon patterns
  200. ;;
  201. ;; With suggestions and minor regex patches from numerous others...
  202. ;;
  203. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  204. ;;
  205. ;; hilit19.el,v
  206. ;; Revision 2.19  1993/09/08  18:44:10  stig
  207. ;; installed patch for elusive bug in hilit-rehighlight-region that caused
  208. ;; hilit-unhighlight-region to hang in an infinite loop.
  209. ;;
  210. ;; Revision 2.18  1993/08/27  03:51:00  stig
  211. ;; minor mods to lisp-mode and c/c++ mode patterns
  212. ;;
  213. ;; Revision 2.17  1993/08/25  02:19:17  stig
  214. ;; work-around for bug in next-overlay-change that caused dired and jargon-mode
  215. ;; to hang in an endless loop.  Perhaps other modes were doing this too.
  216. ;;
  217. ;; Revision 2.16  1993/08/22  19:46:00  stig
  218. ;; bug fix for next-overlay-change and accompanying change to
  219. ;; hilit-unhighlight-region
  220. ;;
  221. ;; Revision 2.15  1993/08/20  12:16:22  stig
  222. ;; minor change to fortran patterns
  223. ;;
  224. ;; Revision 2.14  1993/08/17  14:12:10  stig
  225. ;; added default face mapping for 'formula' which is needed for new latex
  226. ;; patterns.
  227. ;;
  228. ;; twiddled the calendar-mode patterns a bit.
  229. ;;
  230. ;; Revision 2.13  1993/08/16  04:33:54  stig
  231. ;; hilit-set-mode-patterns was screwing up two part patterns.  it doesn't now.
  232. ;;
  233. ;; Revision 2.12  1993/08/16  00:16:41  stig
  234. ;; changed references to default-bold-italic to just bold-italic because the
  235. ;;   font for that face is maintained by emacs.
  236. ;;
  237. ;; the pattern matcher now starts it's searches from the end of the most
  238. ;;   recently highlighted region (which is not necessarily the end of the most
  239. ;;   recently matched regex).
  240. ;;
  241. ;; multiple errors in pattern matcher now just give an error instead of lots of
  242. ;;   annoying messages and dings.
  243. ;;
  244. ;; no longer use vm-summary-mode-hooks.
  245. ;;
  246. ;; some code moved from hilit-highlight-region to hilit-set-mode-patterns.
  247. ;;   This will affect you if you pass your patterns directly to
  248. ;;   hilit-highlight-region....use a pseudo-mode instead.
  249. ;;
  250. ;; pattern changes to C/C++, latex, texinfo, fortran, nroff, etc.
  251. ;;
  252. ;; Revision 2.11  1993/08/13  12:12:37  stig
  253. ;; removed some crufty commented-out code
  254. ;;
  255. ;; diverged lisp-mode and emacs-lisp-mode...also added lisp keywords.
  256. ;;
  257. ;; Revision 2.10  1993/08/13  09:47:06  stig
  258. ;; added calendar-mode, icon-mode and pascal-mode patterns
  259. ;;
  260. ;; commented out hilit-toggle-highlight because I want to phase it out entirely
  261. ;;
  262. ;; Revision 2.9  1993/08/13  08:44:22  stig
  263. ;; added optional case-fold argument to hilit-set-mode-patterns, this case-fold
  264. ;; parameter is now stored in hilit-patterns-alist.
  265. ;;
  266. ;; Revision 2.8  1993/08/12  22:05:03  stig
  267. ;; fixed some typos in documentation
  268. ;;
  269. ;; twiddled some of the color defaults for dark backgrounds
  270. ;;
  271. ;; always get 'mono color defaults if (not (x-display-color-p))
  272. ;;
  273. ;; added hilit-rehighlight-buffer-quietly to dired-after-readin-hook
  274. ;;
  275. ;; fixed bug in hilit-string-find that mishandled strings of the form: "\\"
  276. ;;
  277. ;; NEW FUNCTION: hilit-add-mode-pattern...  kinda like add-hook for patterns
  278. ;;
  279. ;; fixed minor pattern bugs for latex-mode and emacs-lisp-mode
  280. ;;
  281. ;; Revision 2.7  1993/07/30  02:43:01  stig
  282. ;; added const to the list of modifiers for C/C++ types
  283. ;;
  284. ;; Revision 2.6  1993/07/30  00:30:54  stig
  285. ;; now permit selection of arbitrary subexpressions for highlighting...
  286. ;; fixed keyword patterns for C/C++ using this technique.
  287. ;;
  288. ;; Revision 2.5  1993/07/28  05:02:56  stig
  289. ;; improvements to makefile regular expressions
  290. ;; removed about 130 lines just by compacting the big defconst for
  291. ;;   hilit-face-translation-table into a mapcar and defining a separate table
  292. ;;   of default faces.
  293. ;;
  294. ;; Revision 2.4  1993/07/27  14:09:05  stig
  295. ;; documented another "known problem" to "head off gripe mail at the pass."
  296. ;;
  297. ;; Revision 2.3  1993/07/27  02:15:49  stig
  298. ;; (hilit-lookup-face-create) incorporated patch which improves it's behavior
  299. ;; with more than one frame...  Still can't have bold on the same face in two
  300. ;; differrent fonts sizes at the same time...
  301. ;;
  302. ;; Revision 2.2  1993/07/27  02:02:59  stig
  303. ;; vastly improved the makefile patterns
  304. ;; added hook for mh-show-mode
  305. ;;
  306. ;; Revision 2.1  1993/07/24  17:46:21  stig
  307. ;; Phasing out Info-select-hook...  Version 19.18 will use Info-selection-hook.
  308. ;;
  309. ;; Revision 2.0  1993/07/24  13:50:10  stig
  310. ;; better documentation and added the function hilit-submit-feedback.
  311. ;; C-S-l (control shift l) repaints the buffer.  Other bindings are optional.
  312. ;; multi-line highlights no longer cause problems when
  313. ;;   hilit-auto-rehighlight is 'visible
  314. ;; added hilit-predefined-face-list...
  315. ;; changed name of hilit-mode-alist to hilit-patterns-alist
  316. ;; added hilit-message-quietly to mail-setup-hook
  317. ;; added hilit-parser-alist which can be used to apply different patterns to
  318. ;;   different parts of a buffer.  This could be integrated in a far more
  319. ;;   elegant manner, but it presently serves the purpose of not applying
  320. ;;   message header patterns to message bodies in mail-mode and it's kin.
  321. ;; hilit-set-mode-patterns now takes a list of modes and an optional parse-fn
  322. ;;
  323.  
  324. ;;;;;; AND THIS CAN BE APPLIED TO VM 5.33L_19
  325. ;; 
  326. ;; *** ../site/vm5.33L_19/vm-summary.el    Fri Jun  4 22:17:11 1993
  327. ;; --- ./vm-summary.el     Tue Jun 22 16:39:30 1993
  328. ;; ***************
  329. ;; *** 152,158 ****
  330. ;;                   (insert "->")
  331. ;;                   (delete-char 2)
  332. ;;                   (forward-char -2)
  333. ;; !                 (and w vm-auto-center-summary (vm-auto-center-summary))))
  334. ;;             (and old-window (select-window old-window)))))))
  335. ;;   
  336. ;;   (defun vm-mark-for-display-update (message)
  337. ;; --- 152,159 ----
  338. ;;                   (insert "->")
  339. ;;                   (delete-char 2)
  340. ;;                   (forward-char -2)
  341. ;; !                 (and w vm-auto-center-summary (vm-auto-center-summary))
  342. ;; !                 (run-hooks 'vm-summary-pointer-hook)))
  343. ;;             (and old-window (select-window old-window)))))))
  344. ;;   
  345. ;;   (defun vm-mark-for-display-update (message)
  346. ;; 
  347. ;;;;;;
  348.  
  349. ;;; Code:
  350.  
  351. ;; User Options:
  352.  
  353. (defvar hilit-quietly nil
  354.   "* If non-nil, this inhibits progress indicators during highlighting")
  355.  
  356. (defvar hilit-auto-highlight t
  357.   "* T if we should highlight all buffers as we find 'em, nil to disable
  358.   automatic highlighting by the find-file hook.")
  359.  
  360. (defvar hilit-auto-highlight-maxout 60000 ; hilit19 keeps getting bigger...
  361.   "* auto-highlight is disabled in buffers larger than this")
  362.  
  363. (defvar hilit-auto-rehighlight t
  364.   "* If this is non-nil, then hilit-redraw and hilit-recenter will also
  365.   rehighlight part or all of the current buffer.  T will rehighlight the
  366.   whole buffer, a NUMBER will rehighlight that many lines before and after
  367.   the cursor, and the symbol 'visible' will rehighlight only the visible
  368.   portion of the current buffer.  This variable is buffer-local.")
  369.  
  370. (make-variable-buffer-local 'hilit-auto-rehighlight)
  371.  
  372. (defvar hilit-auto-rehighlight-fallback '(20000 . 100)
  373.   "* Cons of the form (THRESHOLD . FALLBACK), where FALLBACK is assigned to
  374.   hilit-auto-rehighlight if the size of a newly opened buffer is larger than
  375.   THRESHOLD.")
  376.  
  377. (defvar hilit-face-check t
  378.   "* T slows down highlighting but permits the user to change fonts without
  379.   losing bold and italic faces...  T causes hilit-lookup-face-create to dig
  380.   through the frame parameters for the current window every time it's called.
  381.   If you never change fonts in emacs, set this to NIL.")
  382.  
  383. ;; Variables which must be set before loading hilit19.
  384.  
  385. (defvar hilit-inhibit-rebinding nil
  386.   "If non-nil, this inhibits replacement of recenter, yank, and yank-pop.")
  387.  
  388. (defvar hilit-inhibit-hooks nil
  389.   "If non-nil, this inhibits installation of hooks for Info, gnus, & vm.")
  390.  
  391. (defvar hilit-background-mode 'light
  392.   "'mono inhibits color, 'dark or 'light indicate the background brightness.")
  393.  
  394. (defvar hilit-mode-enable-list nil
  395.   "If a list of modes to exclusively enable or specifically disable.
  396. The sense of the list is negated if it begins with the symbol 'not'.
  397. Set this variable before you load hilit19.
  398.  
  399. Ex:  (perl-mode jargon-mode c-mode)    ; just perl, C, and jargon modes
  400.      (not text-mode)            ; all modes except text mode")
  401.  
  402. ;; Variables that are not generally modified directly
  403.  
  404. (defvar hilit-parser-alist nil
  405.   "alist of major-mode values and parsers called by hilit-rehighlight-buffer.
  406.  
  407. Parsers for a given mode are IGNORED for partial rehighlights...maybe you'd
  408. like to make this more universal?")
  409.  
  410. (defvar hilit-patterns-alist nil
  411.   "alist of major-mode values and default highlighting patterns
  412.  
  413. A highlighting pattern is a list of the form (start end face), where
  414. start is a regex, end is either a regex or a match number for start, and face
  415. is the name of an entry in hilit-face-translation-table, the name of a face,
  416. or nil (which disables the pattern).
  417.  
  418. Each entry in the alist is of the form:
  419.     (mode . (case-fold pattern [pattern ...]))
  420.  
  421. See the hilit-lookup-face-create documentation for valid face names.")
  422.  
  423. (defvar hilit-predefined-face-list (face-list)
  424.   "List of faces with which hilit-lookup-face-create will NOT tamper.
  425.  
  426. If hilit19 is dumped into emacs at your site, you may have to set this in
  427. your init file.")
  428.  
  429. (eval-when-compile (setq byte-optimize t))
  430.  
  431. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  432. ;; Use this to report bugs:
  433.  
  434. (eval-when-compile (require 'reporter))    ; no compilation gripes
  435.  
  436. (defun hilit-submit-feedback ()
  437.   "Submit feedback on hilit19 to the author: Stig@netcom.com"
  438.   (interactive)
  439.   (require 'reporter)
  440.   (and (y-or-n-p "Do you really want to submit a report on hilit19? ")
  441.        (reporter-submit-bug-report
  442.     "Jonathan Stigelman <Stig@netcom.com>"
  443.     "hilit19.el (Release 2.19)"
  444.     (and (y-or-n-p "Do you need to include a dump hilit variables? ")
  445.          (append
  446.           '(
  447.         hilit-quietly            hilit-inhibit-hooks
  448.         hilit-background-mode        hilit-mode-enable-list
  449.         hilit-auto-highlight        hilit-auto-highlight-maxout
  450.         hilit-auto-rehighlight        hilit-auto-rehighlight-fallback
  451.         hilit-face-check
  452.         )
  453.           (and (y-or-n-p "Have you modified the standard patterns? ")
  454.            (yes-or-no-p "Are your patterns *REALLY* relevant? ")
  455.            '(hilit-parser-alist
  456.              hilit-patterns-alist
  457.              hilit-predefined-face-list
  458.              ))))
  459.      (function
  460.       (lambda ()
  461.         (and (y-or-n-p "Is this a problem with font display? ")
  462.          (insert "\nFrame Configuration:\n====================\n"
  463.              (prin1-to-string (frame-configuration-to-register ?F))
  464.              "\n"
  465.              ))))
  466.      nil
  467.      (concat
  468.       "This is (check all that apply, and delete what's irrelevant):\n"
  469.       "  [ ] a _MASSIVE_THANK_YOU_ for writing hilit19.el\n"
  470.       "  [ ] An invitation to attend the next Hackers Conference\n"
  471.       "  [ ] You're a RIGHTEOUS HACKER, what are your rates?\n"
  472.       "  [ ] I've used the force and read the source, but I'M CONFUSED\n"
  473.       "  [ ] a PATCH. (output of 'diff -uw old.el new.el' or 'diff -cw')\n"
  474.       "  [ ] a SERIOUS AND REPRODUCABLE BUG that is not an EMACS bug\n"
  475.       "     - I *swear* that it's not already mentioned in the KNOWN BUGS\n"
  476.       "     - I HAVE CHECKED netcom.com:/pub/stig/src/Beta/hilit19.el.gz\n"
  477.       "       for a newer release that fixes the problem.\n"
  478.       "    >> I HAVE ALSO CHECKED netcom.com:/pub/stig/src/Beta/hl319.el.gz\n"
  479.       "       This is the alpha version...what will become hilit19 (Beta 3.0).\n"
  480.       "\n"
  481.       "Hey Stig, I *know* you're busy but...\n"))))
  482.  
  483. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  484. ;;
  485. ;; These faces are either a valid face name, or nil
  486. ;; if you want to change them, you must do so AFTER hilit19 is loaded
  487.  
  488. (defconst hilit-default-face-table
  489.   '(
  490.     ;; used for C/C++, elisp, perl, and Icon
  491.     (comment    firebrick-italic    moccasin           italic)
  492.     (include    purple            Plum1           bold-italic)
  493.     (define    ForestGreen-bold    green           bold)
  494.     (defun    blue-bold        cyan-bold           bold-italic)
  495.     (decl    RoyalBlue        cyan           bold)
  496.     (type    nil            yellow           nil)
  497.     (keyword    RoyalBlue        cyan           bold-italic)
  498.     (label    red-underline        orange-underlined  underline)
  499.     (string    grey40            orange           underline)
  500.  
  501.     ;; used for Icon
  502.     (charset    grey50            orange           underline)
  503.     
  504.     ;; some further faces for Ada
  505.     (struct      black-bold        white-bold           bold)
  506.     (glob-struct  magenta        Plum1           default-bold-underline)
  507.     (named-param  DarkGoldenrod        Goldenrod           underline)
  508.     
  509.     ;; and anotherone for LaTeX
  510.     (crossref      DarkGoldenrod        Goldenrod           underline)
  511.     (formula      Goldenrod        DarkGoldenrod      underline)
  512.  
  513.     ;; compilation buffers
  514.     (active-error default/pink-bold  default/DeepPink-bold  default-underline)
  515.     (error      red-bold           yellow           bold)
  516.     (warning      blue-italic         green           italic)
  517.  
  518.     ;; Makefiles (some faces borrowed from C/C++ too)
  519.     (rule      blue-bold-underline cyan-underline   default-bold-underline)
  520.     
  521.     ;; VM, GNUS and Text mode
  522.     (msg-subject    blue-bold       yellow             bold)
  523.     (msg-from        purple-bold        green           bold)
  524.     (msg-header        firebrick-bold  cyan           italic)
  525.     (msg-separator  black/tan-bold  black/lightblue    nil)
  526.     (msg-quote        ForestGreen        pink           italic)
  527.  
  528.     (summary-seen     grey40        white           nil)
  529.     (summary-killed   grey50        white           nil)
  530.     (summary-Xed      OliveDrab2    green           nil)
  531.     (summary-deleted  firebrick        white           italic)
  532.     (summary-unread   RoyalBlue        yellow           bold)
  533.     (summary-new      blue-bold        yellow-bold           bold-italic)
  534.     (summary-current  default/skyblue-bold green/dimgrey-bold reverse-default)
  535.  
  536.     (gnus-group-unsubscribed grey50        white        nil)
  537.     (gnus-group-empty         nil        nil        nil)
  538.     (gnus-group-full         ForestGreen    green        italic)
  539.     (gnus-group-overflowing  firebrick        red        bold-italic)
  540.  
  541.     ;; dired mode
  542.     (dired-directory blue-bold         cyan            bold)
  543.     (dired-link         firebrick-italic  green           italic)
  544.     (dired-ignored   ForestGreen       moccasin           nil)
  545.     (dired-deleted   red-bold-italic   orange           bold-italic)
  546.     (dired-marked    purple           Plum1           nil)
  547.     
  548.     ;; Info-mode, and jargon-mode.el and prep.ai.mit.edu:/pub/gnu/jargon*
  549.     (jargon-entry    blue-bold           cyan            bold)
  550.     (jargon-xref     purple-bold       Plum1           italic)
  551.     (jargon-keyword  firebrick-underline yellow           underline)
  552.     )
  553.   "alist of default faces (face . (light-default dark-default mono-default))
  554.  
  555. There is no way for the user to modify this table such that it will have any
  556. effect upon the translations used by hilit19.  Instead, use the function
  557. hilit-translate AFTER hilit19 has been loaded.
  558.  
  559. See also the documentation for hilit-lookup-face-create.")
  560.  
  561. (defconst hilit-face-translation-table
  562.   (let ((index (or (and (x-display-color-p)
  563.             (cdr (assq hilit-background-mode
  564.                    '((light . 1) (dark . 2)))))
  565.            3)))
  566.     (mapcar (function (lambda (x) (cons (car x) (nth index x))))
  567.         hilit-default-face-table))
  568.   "alist that maps symbolic face-names to real face names")
  569.  
  570. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  571. ;; To translate one face to another...
  572. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  573.  
  574. (defmacro hilit-translate (&rest args)
  575.   "(hilit-translate FROM TO FROM TO ...): translate each face FROM to the
  576. value of its TO face.  This is like setq for faces.
  577.  
  578. The function hilit-lookup-face-create will repeatedly translate until no more
  579. translations for the face exist in the translation table.
  580.  
  581. See the documentation for hilit-lookup-face-create for names of valid faces."
  582.   (or (zerop (% (length args) 2))
  583.       (error "wrong number of args"))
  584.   (let (cmdl from to)
  585.     (while args
  586.       (setq from (car args) to (nth 1 args) args (nthcdr 2 args)
  587.         cmdl (cons (list 'hilit-associate ''hilit-face-translation-table
  588.                  (list 'quote from) to)
  589.                cmdl)))
  590.     (cons 'progn cmdl)))
  591.  
  592. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  593. ;; This function actually translates and then creates the faces...
  594. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  595.  
  596. (defun hilit-lookup-face-create (face &optional force)
  597.   "Get a FACE, or create it if it doesn't exist.  In order for it to
  598. properly create the face, the followwing naming convention must be used:
  599.     [reverse-](fgcolor[/bgcolor])[-bold][-italic][-underline]
  600. Example: (hilit-lookup-face-create 'comment-face) might create and return 'red
  601.  
  602. Each color is either the name of an X color (see .../X11/lib/X11/rgb.txt),
  603. a hexadecimal specification of the form \"hex-[0-9A-Fa-f]+\", or \"default\".
  604.  
  605. An optional argument, FORCE, will cause the face to be recopied from the
  606. default...which is probably of use only if you've changed fonts.
  607.  
  608. See the documentation for hilit-translate and hilit-face-translation-table."
  609.  
  610. ;; translate the face ...
  611.   (let ((trec t) visited)
  612.     (while trec
  613.       (cond ((memq face visited) (error "face translation loop: %S" visited))
  614.         (t (setq visited (cons face visited)
  615.              trec (assq face hilit-face-translation-table))
  616.            (and trec (setq face (cdr trec)))))))
  617.  
  618.   ;; make the face if we need to...
  619.   (let* ((fn (symbol-name face))
  620.      (frame (selected-frame))
  621.      (basefont (cdr (assq 'font (frame-parameters frame))))
  622.      error fgcolor bgcolor)
  623.     (cond
  624.      ((or (null face)            
  625.       (memq face hilit-predefined-face-list))
  626.       ;; do nothing if the face is nil or if it's predefined.
  627.       )
  628.      ((or force
  629.       (not (memq face (face-list)))
  630.       (and hilit-face-check
  631.            (not (string= (get face 'basefont) basefont))))
  632.       (copy-face 'default 'scratch-face)
  633.       (if (string-match "^reverse-?" fn)
  634.       (progn (invert-face 'scratch-face)
  635.          (setq fn (substring fn (match-end 0)))))
  636.  
  637.       ;; parse foreground color
  638.       (if (string-match "^\\(hex-\\)?\\([A-Za-z0-9]+\\)" fn)
  639.       (setq fgcolor (concat
  640.              (if (match-beginning 1) "#")
  641.              (substring fn (match-beginning 2) (match-end 2)))
  642.         fn (substring fn (match-end 0)))
  643.     (error "bad face name %S" face))
  644.  
  645.       ;; parse background color
  646.       (if (string-match "^/\\(hex-\\)?\\([A-Za-z0-9]+\\)" fn)
  647.       (setq bgcolor (concat
  648.              (and (match-beginning 1) "#")
  649.              (substring fn (match-beginning 2) (match-end 2)))
  650.         fn (substring fn (match-end 0))))
  651.       
  652.       (and (string= "default" fgcolor) (setq fgcolor nil))
  653.       (and (string= "default" bgcolor) (setq bgcolor nil))
  654.       
  655.       ;; catch errors if we can't allocate the color(s)
  656.       (condition-case nil
  657.       (progn (set-face-foreground 'scratch-face fgcolor)
  658.          (set-face-background 'scratch-face bgcolor)
  659.          (copy-face 'scratch-face face)
  660.          (put face 'basefont basefont))
  661.     (error (message "couldn't allocate color for '%s'"
  662.             (symbol-name face))
  663.            (setq face 'default)
  664.            (setq error t)))
  665.       (or error
  666.       ;; don't bother w/ bold or italic if we didn't get the color
  667.       ;; we wanted, but ignore errors making the face bold or italic
  668.       ;; if the font isn't available, there's nothing to do about it...
  669.       (progn
  670.         (set-face-font face nil frame)
  671.         (set-face-underline-p face (string-match "underline" fn))
  672.         (if (string-match ".*bold" fn)
  673.         (progn
  674.           ;; first, fix up this frame's face
  675.           (make-face-bold face frame  'noerr)
  676.           ;; now, fix up the face from the global list
  677.           (set-face-font face (face-font face frame) t)))
  678.         (if (string-match ".*italic" fn)
  679.         (progn
  680.           ;; first, fix up this frame's face
  681.           (make-face-italic face frame 'noerr)
  682.           ;; now, fix up the face from the global list
  683.           (set-face-font face (face-font face frame) t)))
  684.         ))
  685.       )))
  686.   face)
  687.  
  688. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  689. ;; Region Highlight/Unhighlight code (Both overlay and text-property versions)
  690. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  691.  
  692. (defsubst hilit-region-set-face (start end face-name &optional prio prop)
  693.   "Highlight region from START to END using FACE and, optionally, PRIO.
  694. The optional 5th arg, PROP is a property to set instead of 'hilit."
  695.   (let ((overlay (make-overlay start end)))
  696.     (overlay-put overlay 'face face-name)
  697.     (overlay-put overlay (or prop 'hilit) t)
  698.     (and prio (overlay-put overlay 'priority prio))))
  699.  
  700. (defun hilit-unhighlight-region (start end &optional quietly)
  701.   "Unhighlights the region from START to END, optionally in a QUIET way"
  702.   (interactive "r")
  703.   (or quietly hilit-quietly (message "Unhighlighting"))
  704.   (let ((lstart 0))
  705.     (while (and start (> start lstart) (< start end))
  706.       (mapcar (function (lambda (ovr)
  707.               (and (overlay-get ovr 'hilit) (delete-overlay ovr))))
  708.           (overlays-at start))
  709.       (setq lstart start start (next-overlay-change start))))
  710.   (or quietly hilit-quietly (message "Done unhighlighting")))
  711.  
  712. ;;;; These functions use text properties instead of overlays.  Text properties
  713. ;;;; are copied through kill and yank...which might be convenient, but is not
  714. ;;;; terribly efficient as of 19.12, ERGO it's been disabled
  715. ;;
  716. ;;(defsubst hilit-region-set-face (start end face-name &optional prio prop)
  717. ;;  "Highlight region from START to END using FACE and, optionally, PRIO.
  718. ;;The optional 5th arg, PROP is a property to set instead of 'hilit."
  719. ;;    (put-text-property start end 'face face-name)
  720. ;;    )
  721. ;;
  722. ;;(defun hilit-unhighlight-region (start end &optional quietly)
  723. ;;  "Unhighlights the region from START to END, optionally in a QUIET way"
  724. ;;  (interactive "r")
  725. ;;  (let ((buffer-read-only nil)
  726. ;;    (bm (buffer-modified-p)))
  727. ;;    (remove-text-properties start end '(face))
  728. ;;    (set-buffer-modified-p bm)))
  729. ;;;;
  730.  
  731. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  732. ;; Pattern Application code and user functions
  733. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  734.  
  735. (defun hilit-highlight-region (start end &optional patterns quietly)
  736.   "Highlights the area of the buffer between START and END (the region when
  737. interactive).  Without the optional PATTERNS argument, the pattern for
  738. major-mode is used.  If PATTERNS is a symbol, then the patterns associated
  739. with that symbol are used.  QUIETLY suppresses progress messages if
  740. non-nil."
  741.   (interactive "r")
  742.   (cond ((null patterns)
  743.      (setq patterns (cdr (assq major-mode hilit-patterns-alist))))
  744.     ((symbolp patterns)
  745.      (setq patterns (cdr (assq patterns hilit-patterns-alist)))))  
  746.   ;; txt prop: (setq patterns (reverse patterns))
  747.   (let ((case-fold-search (car patterns))
  748.     (prio (1- (length patterns)))
  749.     ;; txt prop: (buffer-read-only nil)
  750.     ;; txt prop: (bm (buffer-modified-p))
  751.     p pstart pend face mstart (puke-count 0))
  752.     ;; txt prop: (unwind-protect
  753.     (setq patterns (cdr patterns))    ; remove case-fold from head of pattern
  754.     (save-excursion
  755.       (save-restriction
  756.     (narrow-to-region start end)
  757.     (while patterns
  758.       (setq p (car patterns))
  759.       (setq pstart (car p)
  760.         pend (nth 1 p)
  761.         face (hilit-lookup-face-create (nth 2 p)))
  762.       (if (not face)        ; skipped if nil
  763.           nil
  764.         (or quietly hilit-quietly
  765.         (message "highlighting %d: %s%s" prio pstart 
  766.              (if (stringp pend) (concat " ... " pend) "")))
  767.         (goto-char (point-min))
  768.         (condition-case msg
  769.         (cond 
  770.               ((symbolp pstart)
  771.                ;; inner loop -- special function to find pattern
  772.                (let (region)
  773.              (while (setq region (funcall pstart pend))
  774.                (hilit-region-set-face (car region) (cdr region)
  775.                           face prio))))
  776.               ((stringp pend)
  777.                ;; inner loop -- regex-start ... regex-end
  778.                (while (re-search-forward pstart nil t nil)
  779.              (goto-char (setq mstart (match-beginning 0)))
  780.              (if (re-search-forward pend nil t nil)
  781.                  (hilit-region-set-face mstart (match-end 0)
  782.                             face prio)
  783.                (forward-char 1))))
  784.               ((numberp pend)
  785.                ;; inner loop -- just one regex to match whole pattern
  786.                (while (re-search-forward pstart nil t nil)
  787.              (goto-char (match-end pend))
  788.              (hilit-region-set-face  (match-beginning pend)
  789.                          (match-end pend) face prio)))
  790.               (t (error "malformed pattern")))
  791.           (error (if (> (setq puke-count (1+ puke-count)) 1)
  792.              (error msg)
  793.                (message "Error: '%s'" msg)
  794.                (ding) (sit-for 4)))))
  795.       (setq prio (1- prio)
  796.         patterns (cdr patterns)))
  797.     ))
  798.     (or quietly hilit-quietly (message "")) ; "Done highlighting"
  799.     ;; txt prop: (set-buffer-modified-p bm)) ; unwind protection
  800.     ))
  801.  
  802. (defun hilit-rehighlight-region (start end &optional quietly)
  803.   "Re-highlights the region, optionally in a QUIET way"
  804.   (interactive "r")
  805.   (save-restriction
  806.     (widen)
  807.     (setq start (apply 'min start (mapcar 'overlay-start (overlays-at start)))
  808.       end (apply 'max end (mapcar 'overlay-end (overlays-at end))))
  809.     (hilit-unhighlight-region start end quietly)
  810.     (hilit-highlight-region   start end nil quietly)))
  811.  
  812. (defun hilit-rehighlight-buffer (&optional quietly)
  813.   "Re-highlights the buffer, optionally in a QUIET way"
  814.   (interactive "")
  815.   (let ((parse-fn (cdr (assq major-mode hilit-parser-alist))))
  816.     (if parse-fn
  817.     (funcall parse-fn quietly)
  818.       (hilit-rehighlight-region (point-min) (point-max) quietly)))
  819.   nil)
  820.  
  821. (defun hilit-rehighlight-buffer-quietly ()
  822.   (hilit-rehighlight-buffer t))
  823.  
  824. (defun hilit-rehighlight-message (quietly)
  825.   "Highlight a buffer containing a news article or mail message."
  826.   (save-excursion
  827.     (goto-char (point-min))
  828.     (re-search-forward "^$" nil 'noerr)
  829.     (hilit-unhighlight-region (point-min) (point-max) quietly)
  830.     (hilit-highlight-region (point-min) (point) 'msg-header quietly)
  831.     (hilit-highlight-region (point) (point-max) 'msg-body quietly)))
  832.  
  833. (defalias 'hilit-highlight-buffer 'hilit-rehighlight-buffer)
  834.  
  835. ;; Well, I want to remove this function...there's one sure way to find out if
  836. ;; anyone uses it or not...and that's to comment it out.
  837. ;; 
  838. ;; (defun hilit-toggle-highlight (arg)
  839. ;;   "Locally toggle highlighting.  With arg, forces highlighting off."
  840. ;;   (interactive "P")
  841. ;;   ;; FIXME -- this loses numeric information in hilit-auto-rehighlight
  842. ;;   (setq hilit-auto-rehighlight
  843. ;;         (and (not arg) (not hilit-auto-rehighlight)))
  844. ;;   (if hilit-auto-rehighlight
  845. ;;       (hilit-rehighlight-buffer)
  846. ;;     (hilit-unhighlight-region (point-min) (point-max)))
  847. ;;   (message "Rehighlighting is set to %s" hilit-auto-rehighlight))
  848.  
  849. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  850. ;; HOOKS
  851. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  852.  
  853. (defun hilit-find-file-hook ()
  854.   "Find-file hook for hilit package.  See the variable hilit-auto-highlight."
  855.   (cond ((and hilit-auto-highlight
  856.           (assq major-mode hilit-patterns-alist))
  857.      (if (> buffer-saved-size (car hilit-auto-rehighlight-fallback))
  858.          (setq hilit-auto-rehighlight
  859.            (cdr hilit-auto-rehighlight-fallback)))
  860.      (if (> buffer-saved-size hilit-auto-highlight-maxout) nil
  861.        (hilit-rehighlight-buffer)
  862.        (set-buffer-modified-p nil)))))
  863.  
  864. (defun hilit-repaint-command (arg)
  865.   "Rehighlights according to the value of hilit-auto-rehighlight, or the
  866. prefix argument if that is specified.
  867. \t\\[hilit-repaint-command]\t\trepaint according to hilit-auto-rehighlight
  868. \t^U \\[hilit-repaint-command]\trepaint entire buffer
  869. \t^U - \\[hilit-repaint-command]\trepaint visible portion of buffer
  870. \t^U n \\[hilit-repaint-command]\trepaint n lines to either side of point"
  871.   (interactive "P") 
  872.   (let (st en quietly)
  873.     (or arg (setq arg hilit-auto-rehighlight))
  874.     (cond ((or (eq  arg 'visible) (eq arg '-))
  875.        (setq st (window-start) en (window-end) quietly t))
  876.       ((numberp arg)
  877.        (setq st (save-excursion (forward-line (- arg)) (point))
  878.          en (save-excursion (forward-line arg) (point))))
  879.       (arg
  880.        (hilit-rehighlight-buffer)))
  881.     (if st
  882.       (hilit-rehighlight-region st en quietly))))
  883.  
  884. (defun hilit-recenter (arg)
  885.   "Recenter, then rehighlight according to hilit-auto-rehighlight.  If called
  886. with an unspecified prefix argument (^U but no number), then a rehighlight of
  887. the entire buffer is forced."
  888.   (interactive "P")
  889.   (recenter arg)
  890.   ;; force display update
  891.   (sit-for 0)
  892.   (hilit-repaint-command (consp arg)))
  893.  
  894. (defun hilit-yank (arg)
  895.   "Yank with rehighlighting"
  896.   (interactive "*P")
  897.   (let ((transient-mark-mode nil))
  898.     (yank arg)
  899.     (and hilit-auto-rehighlight
  900.      (hilit-rehighlight-region (region-beginning) (region-end) t))
  901.     (setq this-command 'yank)))
  902.  
  903. (defun hilit-yank-pop (arg)
  904.   "Yank-pop with rehighlighting"
  905.   (interactive "*p")
  906.   (let ((transient-mark-mode nil))
  907.     (yank-pop arg)
  908.     (and hilit-auto-rehighlight
  909.      (hilit-rehighlight-region (region-beginning) (region-end) t))
  910.     (setq this-command 'yank)))
  911.  
  912. ;;; this line highlighting stuff is untested.  play with it only if you feel
  913. ;;; adventurous...don't ask me to fix it...though you're welcome to.  -- Stig
  914. ;; 
  915. ;; (defun hilit-rehighlight-line-quietly (&rest args)
  916. ;;   "Quietly rehighlight just this line.
  917. ;; Useful as an after change hook in VM/gnus summary buffers and dired buffers.
  918. ;; If only there were an after-change-function, that is..."
  919. ;;   (save-excursion
  920. ;;     (push-mark nil t)
  921. ;;     (hilit-rehighlight-yank-region)
  922. ;;     (and orig-achange-function (apply orig-achange-function args))))
  923. ;; 
  924. ;; (defun hilit-install-line-hooks ()
  925. ;;   (make-variable-buffer-local 'after-change-function)
  926. ;;   (make-local-variable 'orig-achange-function)
  927. ;;   (setq orig-achange-function after-change-function)
  928. ;;   (setq after-change-function 'hilit-rehighlight-line-quietly))
  929.  
  930. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  931. ;; Wysiwyg Stuff...  take it away and build a whole package around it!
  932. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  933. ;; 
  934. ;; ; For the Jargon-impaired, WYSIWYG === What You See Is What You Get
  935. ;; ; Sure, it sucks to type.  Oh, well.
  936. ;; (defun hilit-wysiwyg-replace ()
  937. ;;   "Replace overstruck text with normal text that's been overlayed with the 
  938. ;; appropriate text attribute.  Suitable for a find-file hook."
  939. ;;   (save-excursion
  940. ;;     (goto-char (point-min))
  941. ;;     (let ((wysb (hilit-lookup-face-create 'wysiwyg-bold))
  942. ;;       (wysu (hilit-lookup-face-create 'wysiwyg-underline))
  943. ;;       (bmod (buffer-modified-p)))
  944. ;;       (while (re-search-forward "\\(.\b.\\)+" nil t)
  945. ;;     (let ((st (match-beginning 0)) (en (match-end 0)))
  946. ;;       (goto-char st)
  947. ;;       (if (looking-at "_")
  948. ;;           (hilit-region-set-face st en wysu 100 'wysiwyg)
  949. ;;         (hilit-region-set-face st en wysb 100 'wysiwyg))
  950. ;;       (while (and (< (point) en) (looking-at ".\b"))
  951. ;;         (replace-match "") (forward-char))
  952. ;;       ))
  953. ;;       (set-buffer-modified-p bmod))))
  954. ;; 
  955. ;; ; is this more appropriate as a write-file-hook or a write-contents-hook?
  956. ;; (defun hilit-wysiwyg-write-repair ()
  957. ;;   "Replace wysiwyg overlays with overstrike text."
  958. ;;   (message "*sigh* hilit-wysiwyg-write-repair not implemented yet")
  959. ;;
  960. ;; For efficiency, this hook should copy the current buffer to a scratch
  961. ;; buffer and do it's overstriking there.  Overlays are not copied, so it'll
  962. ;; be necessary to hop back and forth.  This is OK since you're not fiddling
  963. ;; with--making or deleting--any overlays.  THEN write the new buffer,
  964. ;; delete it, and RETURN T. << important
  965. ;;
  966. ;; Just so you know...there is already an emacs function called
  967. ;; underline-region that does underlining.  I think that the thing to do is
  968. ;; extend that to do overstriking as well.
  969. ;;
  970. ;;  (while (< start end)
  971. ;;    (mapcar (function (lambda (ovr)
  972. ;;              (and (overlay-get ovr 'hilit) (delete-overlay ovr))))
  973. ;;        (overlays-at start))
  974. ;;    (setq start (next-overlay-change start)))
  975. ;;  nil)
  976.  
  977. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  978. ;; Initialization.  
  979. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  980.  
  981. (and (not hilit-inhibit-rebinding)
  982.      window-system
  983.      (progn 
  984.        (substitute-key-definition 'yank     'hilit-yank
  985.                   (current-global-map))
  986.        (substitute-key-definition 'yank-pop 'hilit-yank-pop
  987.                   (current-global-map))
  988.        (substitute-key-definition 'recenter 'hilit-recenter
  989.                   (current-global-map))))
  990.  
  991. (global-set-key [?\C-\S-l] 'hilit-repaint-command)
  992.  
  993. (and window-system
  994.      (add-hook 'find-file-hooks 'hilit-find-file-hook t))
  995.  
  996. (eval-when-compile (require 'gnus))    ; no compilation gripes
  997.  
  998. (and (not hilit-inhibit-hooks)
  999.      window-system
  1000.      (condition-case c
  1001.      (progn
  1002.  
  1003.        ;; BUFFER highlights...
  1004.        (mapcar (function
  1005.             (lambda (hook)
  1006.               (add-hook hook 'hilit-rehighlight-buffer-quietly)))
  1007.            '(
  1008.              Info-selection-hook
  1009.  
  1010. ;; runs too early             vm-summary-mode-hooks
  1011.              vm-summary-pointer-hook
  1012.              vm-preview-message-hook
  1013.              vm-show-message-hook
  1014.  
  1015.              gnus-article-prepare-hook
  1016.              gnus-summary-prepare-hook
  1017.              gnus-group-prepare-hook
  1018.  
  1019.              rmail-show-message-hook
  1020.              mail-setup-hook 
  1021.              mh-show-mode-hook
  1022.  
  1023.              dired-after-readin-hook
  1024.              ))
  1025.  
  1026.        ;; rehighlight only visible part of summary buffer for speed.
  1027.        (add-hook 'gnus-mark-article-hook
  1028.              (function
  1029.               (lambda ()
  1030.             (or (memq gnus-current-article gnus-newsgroup-marked)
  1031.                 (gnus-summary-mark-as-read gnus-current-article))
  1032.             (gnus-summary-set-current-mark)
  1033.             (save-excursion
  1034.               (set-buffer gnus-summary-buffer)
  1035.               (hilit-rehighlight-region (window-start)
  1036.                             (window-end) t)
  1037.               ))))
  1038.        ;; only need prepare article hook
  1039.        ;;
  1040.        ;;    (add-hook 'gnus-select-article-hook
  1041.        ;;          '(lambda () (save-excursion
  1042.        ;;                (set-buffer gnus-article-buffer)
  1043.        ;;                (hilit-rehighlight-buffer))))
  1044.        )
  1045.        (error (message "Error loading highlight hooks: %s" c)
  1046.           (ding) (sit-for 1))))
  1047.  
  1048. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1049. ;; Default patterns for various modes.
  1050. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1051.  
  1052. ;;; do I need this?  I changed the defconst to a defvar because defconst is
  1053. ;;; inappropriate, but I don't know why I wanted hilit-patterns-alist to be
  1054. ;;; reset on every reload...
  1055.  
  1056. (setq hilit-patterns-alist nil) 
  1057.  
  1058. (defun hilit-associate (alist key val)
  1059.   "creates, or destructively replaces, the pair (key . val) in alist"
  1060.   (let ((oldentry (assq key (eval alist))))
  1061.     (if oldentry
  1062.     (setcdr oldentry val)
  1063.       (set alist (cons (cons key val) (eval alist))))))
  1064.   
  1065. (defun hilit-set-mode-patterns (modelist patterns
  1066.                      &optional parse-fn case-fold)
  1067.   "Sets the default highlighting patterns for MODE to PATTERNS.
  1068. See the variable hilit-mode-enable-list.
  1069.  
  1070. Takes optional arguments PARSE-FN and CASE-FOLD."
  1071.   ;; change pattern
  1072.   (mapcar (function (lambda (p)
  1073.               (and (stringp (car p))
  1074.                (null (nth 1 p))
  1075.                (setcar (cdr p) 0))))
  1076.       patterns)
  1077.   (setq patterns (cons case-fold patterns))
  1078.   
  1079.   (or (consp modelist) (setq modelist (list modelist)))
  1080.   (let (ok (flip (eq (car hilit-mode-enable-list) 'not)))
  1081.     (mapcar (function
  1082.          (lambda (m)
  1083.            (setq ok (or (null hilit-mode-enable-list)
  1084.                 (memq m hilit-mode-enable-list)))
  1085.            (and flip (setq ok (not ok)))
  1086.            (and ok
  1087.             (progn
  1088.               (and parse-fn
  1089.                (hilit-associate 'hilit-parser-alist m parse-fn))
  1090.               (hilit-associate 'hilit-patterns-alist m patterns)))))
  1091.         modelist)))
  1092.  
  1093. (defun hilit-add-pattern (pstart pend face &optional mode first)
  1094.   "Highlight pstart with face for the current major-mode.
  1095. Optionally, place the new pattern first in the pattern list"
  1096.   (interactive "sPattern start regex: \nsPattern end regex (default none): \nxFace: ")
  1097.  
  1098.   (and (equal pstart "") (error "Must specify starting regex"))
  1099.   (cond ((equal pend "") (setq pend 0))
  1100.     ((string-match "^[0-9]+$" pend) (setq pend (string-to-int pend))))
  1101.   (or mode (setq mode major-mode))
  1102.   (let ((old-patterns (cdr (assq mode hilit-patterns-alist)))
  1103.     (new-pat (list pstart pend face)))
  1104.     (cond ((not old-patterns)
  1105.        (hilit-set-mode-patterns mode (list new-pat)))
  1106.       (first
  1107.        (setcdr old-patterns (cons new-pat (cdr old-patterns))))
  1108.       (t 
  1109.        (nconc old-patterns (list new-pat)))))
  1110.   (and (interactive-p) (hilit-rehighlight-buffer)))
  1111.  
  1112. (defun hilit-string-find (qchar)
  1113.   "looks for a string and returns (start . end) or NIL.  The argument QCHAR
  1114. is the character that would precede a character constant double quote.
  1115. Finds strings delimited by double quotes.  The first double quote may not be
  1116. preceded by QCHAR and the closing double quote may not be preceded by an odd
  1117. number of backslashes."
  1118.   (let (st en)
  1119.     (while (and (search-forward "\"" nil t)
  1120.         (eq qchar (char-after (1- (setq st (match-beginning 0)))))))
  1121.     (while (and (search-forward "\"" nil t)
  1122.         (save-excursion
  1123.           (setq en (point))
  1124.           (forward-char -1)
  1125.           (skip-chars-backward "\\\\")
  1126.           (forward-char 1)
  1127.           (not (zerop (% (- en (point)) 2))))))
  1128.     (and en (cons st en))))    
  1129.  
  1130. ;; return types on same line...
  1131. ;; ("^[a-zA-z].*\\(\\w\\|[$_]\\)+\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
  1132.  
  1133. ;; On another note, a working pattern for grabbing function definitions for C is
  1134. ;; 
  1135. ;; ("^[a-zA-Z_]+.*[;{]$" nil ForestGreen)  ; global defns ( start at col 1 )
  1136. ;; ("^[a-zA-Z_]+.*(" ")" defun)
  1137. ;; ; defuns assumed to start at col 1, not with # or {
  1138. ;; 
  1139. ;; this will make external declarations/definitions green, and function
  1140. ;; definitions the defun face.  Hmmm - seems to work for me anyway.
  1141.  
  1142. (let ((comments     '(("/\\*" "\\*/" comment)))
  1143.       (c++-comments '(("//.*$" nil comment)
  1144.               ("^/.*$" nil comment)))
  1145.       (strings      '((hilit-string-find ?' string)))
  1146.       (preprocessor '(("^#[ \t]*\\(undef\\|define\\).*$" "[^\\]$" define)
  1147.               ("^#.*$" nil include))))
  1148.  
  1149.   (hilit-set-mode-patterns
  1150.    '(c-mode c++-c-mode elec-c-mode)
  1151.    (append
  1152.     comments strings preprocessor
  1153.     '(
  1154.       ;; function decls are expected to have types on the previous line
  1155.       ("^\\(\\w\\|[$_]\\)+\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
  1156.       ("^\\(typedef\\|struct\\|union\\|enum\\).*$" nil decl)
  1157.       ;; datatype -- black magic regular expression
  1158.       ("[ \n\t({]\\(\\(const\\|register\\|volatile\\|unsigned\\|extern\\|static\\)\\s +\\)*\\(\\(\\w\\|[$_]\\)+_t\\|float\\|double\\|void\\|char\\|short\\|int\\|long\\|FILE\\|\\(\\(struct\\|union\\|enum\\)\\([ \t]+\\(\\w\\|[$_]\\)*\\)\\)\\)\\(\\s +\\*+)?\\|[ \n\t;()]\\)" nil type)
  1159.       ;; key words
  1160.       ("[^_]\\<\\(return\\|goto\\|if\\|else\\|case\\|default\\|switch\\|break\\|continue\\|while\\|do\\|for\\)\\>[^_]" 1 keyword)
  1161.       )))
  1162.  
  1163.   (hilit-set-mode-patterns
  1164.    'c++-mode
  1165.    (append
  1166.     comments c++-comments strings preprocessor
  1167.     '(
  1168.       ;; function decls are expected to have types on the previous line
  1169.       ("^\\(\\(\\w\\|[$_]\\)+::\\)?\\(\\w\\|[$_]\\)+\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
  1170.       ("^\\(\\(\\w\\|[$_]\\)+[ \t]*::[ \t]*\\)?\\(\\(\\w\\|[$_]\\)+\\|operator.*\\)\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
  1171.       ("^\\(template\\|typedef\\|struct\\|union\\|class\\|enum\\|public\\|private\\|protected\\).*$" nil decl)
  1172.       ;; datatype -- black magic regular expression
  1173.       ("[ \n\t({]\\(\\(const\\|register\\|volatile\\|unsigned\\|extern\\|static\\)\\s +\\)*\\(\\(\\w\\|[$_]\\)+_t\\|float\\|double\\|void\\|char\\|short\\|int\\|long\\|FILE\\|\\(\\(struct\\|union\\|enum\\|class\\)\\([ \t]+\\(\\w\\|[$_]\\)*\\)\\)\\)\\(\\s +\\*+)?\\|[ \n\t;()]\\)" nil type)
  1174.       ;; key words
  1175.       ("[^_]\\<\\(return\\|goto\\|if\\|else\\|case\\|default\\|switch\\|break\\|continue\\|while\\|do\\|for\\|public\\|protected\\|private\\|delete\\|new\\)\\>[^_]"
  1176.        1 keyword)))))
  1177.  
  1178. (hilit-set-mode-patterns
  1179.  'perl-mode
  1180.  '(("\\s #.*$" nil comment)
  1181.    ("^#.*$" nil comment)
  1182.    ("\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"" nil string)
  1183.    ("^\\(__....?__\\|\\s *\\sw+:\\)" nil label)
  1184.    ("^require.*$" nil include)
  1185.    ("^package.*$" nil decl)
  1186.    ("^\\s *sub\\s +\\(\\w\\|[_']\\)+" nil defun)
  1187.    ("\\b\\(do\\|if\\|unless\\|while\\|until\\|else\\|elsif\\|for\\|foreach\\|continue\\|next\\|redo\\|last\\|goto\\|return\\|die\\|exit\\)\\b" nil keyword)))
  1188.  
  1189. (hilit-set-mode-patterns
  1190.  'ada-mode
  1191.  '(;; comments
  1192.    ("--.*$" nil comment)
  1193.    ;; main structure
  1194.    ("[ \t\n]procedure[ \t]" "\\([ \t]\\(is\\|renames\\)\\|);\\)" glob-struct)
  1195.    ("[ \t\n]task[ \t]" "[ \t]is" glob-struct)
  1196.    ("[ \t\n]function[ \t]" "return[ \t]+[A-Za-z_0-9]+[ \t]*\\(is\\|;\\|renames\\)" glob-struct)
  1197.    ("[ \t\n]package[ \t]" "[ \t]\\(is\\|renames\\)" glob-struct)
  1198.    ;; if there is nothing before "private", it is part of the structure
  1199.    ("^[ \t]*private[ \t\n]" nil glob-struct)
  1200.    ;; if there is no indentation before the "end", then it is most
  1201.    ;; probably the end of the package
  1202.    ("^end.*$" ";" glob-struct)
  1203.    ;; program structure -- "null", "delay" and "terminate" omitted
  1204.    ("[ \n\t]\\(in\\|out\\|select\\|if\\|else\\|case\\|when\\|and\\|or\\|not\\|accept\\|loop\\|do\\|then\\|elsif\\|else\\|for\\|while\\|exit\\)[ \n\t;]" nil struct)
  1205.    ;; block structure
  1206.    ("[ \n\t]\\(begin\\|end\\|declare\\|exception\\|generic\\|raise\\|return\\|package\\|body\\)[ \n\t;]" nil struct)
  1207.    ;; type declaration
  1208.    ("^[ \t]*\\(type\\|subtype\\).*$" ";" decl)
  1209.    ("[ \t]+is record.*$" "end record;" decl)
  1210.    ;; "pragma", "with", and "use" are close to C cpp directives
  1211.    ("^[ \t]*\\(with\\|pragma\\|use\\)" ";" include)
  1212.    ;; nice for named parameters, but not so beautiful in case statements
  1213.    ("[A-Za-z_0-9.]+[ \t]*=>"   nil named-param)
  1214.    ;; string constants probably not everybody likes this one
  1215.    ("\"" ".*\"" string)))
  1216.  
  1217. (hilit-set-mode-patterns
  1218.  'fortran-mode
  1219.  '(("^[*Cc].*$" nil comment)
  1220.    ("'[^'\n]*'" nil string)
  1221.    ("\\(^[ \t]*[0-9]+\\|[ \t]continue[ \t\n]\\|format\\)" nil define)
  1222.    ("[ \t]\\(do\\|do[ \t]*[0-9]+\\|go[ \t]*to[ \t]*[0-9]+\\|end[ \t]*do\\|if\\|else[ \t]*if\\|then\\|else\\|end[ \t]*if\\)[ \t\n(]" nil define)
  1223.    ("[ \t]\\(call\\|program\\|subroutine\\|function\\|stop\\|return\\|end\\|include\\)[ \t\n]" nil include)
  1224.    ("[ \t]\\(parameter[\t\n ]*([^)]*)\\|data\\|save\\|common[ \t\n]*/[^/]*/\\)" 
  1225.     nil decl)
  1226.    ("^     ." nil type)
  1227.    ("implicit[ \t]*none" nil decl)
  1228.    ("\\([ \t]\\|implicit[ \t]*\\)\\(dimension\\|integer\\|real\\|double[ \t]*precision\\|character\\|logical\\|complex\\|double[ \t]*complex\\)\\([*][0-9]*\\|[ \t\n]\\)" nil keyword)
  1229.    )
  1230.  nil 'case-insensitive)
  1231.  
  1232. (hilit-set-mode-patterns
  1233.  '(m2-mode modula-2-mode)
  1234.  '(("(\\*" "\\*)" comment)
  1235.    (hilit-string-find ?\\ string)
  1236.    ("^[ \t]*PROCEDURE[ \t]+\\w+[^ \t(;]*" nil defun)
  1237.    ("\\<\\(RECORD\\|ARRAY\\|OF\\|POINTER\\|TO\\|BEGIN\\|END\\|FOR\\|IF\\|THEN\\|ELSE\\|ELSIF\\|CASE\\|WHILE\\|DO\\|MODULE\\|FROM\\|RETURN\\|IMPORT\\|EXPORT\\|VAR\\|LOOP\\|UNTIL\\|\\DEFINITION\\|IMPLEMENTATION\\|AND\\|OR\\|NOT\\|CONST\\|TYPE\\|QUALIFIED\\)\\>" nil keyword)
  1238.    )
  1239.  nil 'case-insensitive)
  1240.  
  1241. (hilit-set-mode-patterns 'prolog-mode
  1242.  '(("/\\*" "\\*/" comment)
  1243.    ("%.*$" nil comment)
  1244.    (":-" nil defun)
  1245.    ("!" nil label)
  1246.    ("\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"" nil string)
  1247.    ("\\b\\(is\\|mod\\)\\b" nil keyword)
  1248.    ("\\(->\\|-->\\|;\\|==\\|\\\\==\\|=<\\|>=\\|<\\|>\\|=\\|\\\\=\\|=:=\\|=\\\.\\\.\\|\\\\\\\+\\)" nil decl)
  1249.    ("\\(\\\[\\||\\|\\\]\\)" nil include)))
  1250.  
  1251. (hilit-set-mode-patterns
  1252.  '(
  1253.    LaTeX-mode japanese-LaTeX-mode SliTeX-mode
  1254.    japanese-SliTeX-mode FoilTeX-mode latex-mode
  1255.    )
  1256.  '(
  1257.    ;; comments
  1258.    ("[^\\]%.*$" nil comment)
  1259.  
  1260.    ;; the following two match \foo[xx]{xx} or \foo*{xx} or \foo{xx}
  1261.    ("\\\\\\(sub\\)*\\(paragraph\\|section\\)\\(\*\\|\\[.*\\]\\)?{" "}"
  1262.     keyword)
  1263.    ("\\\\\\(chapter\\|part\\)\\(\*\\|\\[.*\\]\\)?{" "}" keyword)
  1264.    ("\\\\footnote\\(mark\\|text\\)?{" "}" keyword)
  1265.    ("\\\\[a-z]+box" nil keyword)
  1266.    ("\\\\\\(v\\|h\\)space\\(\*\\)?{" "}" keyword)
  1267.  
  1268.    ;; (re-)define new commands/environments/counters
  1269.    ("\\\\\\(re\\)?new\\(environment\\|command\\){" "}" defun)
  1270.    ("\\\\new\\(length\\|theorem\\|counter\\){" "}" defun)
  1271.  
  1272.    ;; various declarations/definitions
  1273.    ("\\\\\\(setlength\\|settowidth\\|addtolength\\|setcounter\\|addtocounter\\)" nil define)
  1274.    ("\\\\\\(title\\|author\\|date\\|thanks\\){" "}" define)
  1275.  
  1276.    ("\\\\documentstyle\\(\\[.*\\]\\)?{" "}" decl)
  1277.    ("\\\\\\(begin\\|end\\|nofiles\\|includeonly\\){" "}" decl)
  1278.    ("\\\\\\(raggedright\\|makeindex\\|makeglossary\\|maketitle\\)\\b" nil
  1279.     decl)
  1280.    ("\\\\\\(pagestyle\\|thispagestyle\\|pagenumbering\\){" "}" decl)
  1281.    ("\\\\\\(normalsize\\|small\\|footnotesize\\|scriptsize\\|tiny\\|large\\|Large\\|LARGE\\|huge\\|Huge\\)\\b" nil decl)
  1282.    ("\\\\\\(appendix\\|tableofcontents\\|listoffigures\\|listoftables\\)\\b"
  1283.     nil decl)
  1284.    ("\\\\\\(bf\\|em\\|it\\|rm\\|sf\\|sl\\|ss\\|tt\\)\\b" nil decl)
  1285.  
  1286.    ;; label-like things
  1287.    ("\\\\item\\(\\[[^]]*\\]\\)?" nil label)
  1288.    ("\\\\caption\\(\\[[^]]*\\]\\)?{" "}" label)
  1289.  
  1290.    ;; formulas
  1291.    ("\\\\("  "\\\\)" formula)                   ; \( \)
  1292.    ("\\\\\\[" "\\\\\\]" formula)                ; \[ \]
  1293.    ("[^$]\\($\\($[^$]*\\$\\|[^$]*\\)\\$\\)" 1 formula) ; '$...$' or '$$...$$'
  1294.    
  1295.    ;; things that bring in external files
  1296.    ("\\\\\\(include\\|input\\|bibliography\\){" "}" include)
  1297.  
  1298.    ;; "wysiwyg" emphasis -- these don't work with nested expressions
  1299.    ;; ("{\\\\\\(em\\|it\\|sl\\)" "}" italic)
  1300.    ;; ("{\\\\bf" "}" bold)
  1301.  
  1302.    ("``" "''" string)
  1303.  
  1304.    ;; things that do some sort of cross-reference
  1305.    ("\\\\\\(\\(no\\)?cite\\|\\(page\\)?ref\\|label\\|index\\|glossary\\){" "}" crossref)
  1306.    ))
  1307.  
  1308. (hilit-set-mode-patterns
  1309.  'bibtex-mode
  1310.  '(;;(";.*$"            nil    comment)
  1311.    ("%.*$"            nil    comment)
  1312.    ("@[a-zA-Z]+"        nil    keyword)
  1313.    ("{[ \t]*[-a-z:_A-Z0-9]+,"    nil    label) ; is wrong sometimes
  1314.    ("^[ \t]*[a-zA-Z]+[ \t]*="    nil    define)))
  1315.  
  1316. (hilit-set-mode-patterns
  1317.  'compilation-mode
  1318.  '(
  1319.    ("^[-_.\"A-Za-z0-9]+\\(:\\|, line \\)[0-9]+: warning:.*$" nil warning)
  1320.    ("^[-_.\"A-Za-z0-9]+\\(:\\|, line \\)[0-9]+:.*$" nil error)
  1321.    ))
  1322.  
  1323. (hilit-set-mode-patterns
  1324.  'makefile-mode
  1325.  '(("^#.*$" nil comment)
  1326.    ("[^$]#.*$" nil comment)
  1327.    ;; rules
  1328.    ("^[^ \t\n]*%[^ \t\n]*[ \t]*::?[ \t]*[^ \t\n]*[ \t]*\\(#.*\\)?$" nil rule)
  1329.    ("^[.][A-Za-z][A-Za-z]?\..*$" nil rule)
  1330.    ;; variable definition
  1331.    ("^[_A-Za-z0-9]+[ \t]*\+?=" nil define)
  1332.    ("\\( \\|:=\\)[_A-Za-z0-9]+[ \t]*\\+=" nil define)
  1333.    ;; variable references
  1334.    ("\\$\\([^ \t\n{(]\\|[{(]@?[_A-Za-z0-9:.,%/=]+[)}]\\)" nil keyword)
  1335.    ("^[A-Za-z0-9.,/_-]+[ \t]*:.*$" nil defun)
  1336.    ("^include " nil include)))
  1337.  
  1338. (let* ((header-patterns '(("^Subject:.*$" nil msg-subject)
  1339.               ("^From:.*$" nil msg-from)
  1340.               ("^--text follows this line--$" nil msg-separator)
  1341.               ("^[A-Za-z][A-Za-z0-9-]+:" nil msg-header)))
  1342.        (body-patterns '(("^\\(In article\\|[ \t]*\\w*[]<>}|]\\).*$"
  1343.              nil msg-quote)))
  1344.        (message-patterns (append header-patterns body-patterns)))
  1345.   (hilit-set-mode-patterns 'msg-header header-patterns)
  1346.   (hilit-set-mode-patterns 'msg-body body-patterns)
  1347.   (hilit-set-mode-patterns '(vm-mode text-mode mail-mode rmail-mode
  1348.                  gnus-article-mode news-reply-mode mh-show-mode)
  1349.                message-patterns
  1350.                'hilit-rehighlight-message))
  1351.  
  1352. (hilit-set-mode-patterns
  1353.  'gnus-group-mode
  1354.  '(("^U.*$" nil gnus-group-unsubscribed)
  1355.    ("^ +[01]?[0-9]:.*$" nil gnus-group-empty)
  1356.    ("^ +[2-9][0-9]:.*$" nil gnus-group-full)
  1357.    ("^ +[0-9][0-9][0-9]+:.*$" nil gnus-group-overflowing)))
  1358.  
  1359. (hilit-set-mode-patterns
  1360.  'gnus-summary-mode
  1361.  '(("^D +[0-9]+: \\[.*$" nil summary-seen)
  1362.    ("^K +[0-9]+: \\[.*$" nil summary-killed)
  1363.    ("^X +[0-9]+: \\[.*$" nil summary-Xed)
  1364.    ("^- +[0-9]+: \\[.*$" nil summary-unread)
  1365.    ("^. +[0-9]+:\\+\\[.*$" nil summary-current)
  1366.    ("^  +[0-9]+: \\[.*$" nil summary-new)
  1367.    ))
  1368.  
  1369. (hilit-set-mode-patterns
  1370.  'vm-summary-mode
  1371.  '(("^   .*$" nil summary-seen)
  1372.    ("^->.*$" nil  summary-current)
  1373.    ("^  D.*$" nil summary-deleted)
  1374.    ("^  U.*$" nil summary-unread)
  1375.    ("^  N.*$" nil summary-new)))
  1376.  
  1377.  
  1378. ;;; this will match only comments w/ an even (zero is even) number of quotes...
  1379. ;;; which is still inadequate because it matches comments in multi-line strings
  1380. ;;; how anal do you want to get about never highlighting comments in strings?
  1381. ;;; I could twiddle with this forever and still it wouldn't be perfect.
  1382. ;;;   (";\\([^\"\n]*\"[^\"\n]*\"\\)*[^\"\n]*$" nil comment)
  1383.  
  1384. (hilit-set-mode-patterns
  1385.  '(emacs-lisp-mode lisp-interaction-mode)
  1386.  '(
  1387.    (";.*" nil comment)
  1388.  
  1389. ;;; This almost works...but I think I'll stick with the parser function 
  1390. ;;;("[^?]\\(\"\\(\"\\||\\([^\"]+\\|[\\]\\([\\][\\]\\)*\"\\)*\"\\)\\)" 1 string)
  1391.    (hilit-string-find ?\\ string)
  1392.  
  1393.    ("^\\s *(def\\(un\\|macro\\|advice\\|alias\\|subst\\)[ \t\n]"
  1394.     "\\()\\|nil\\)" defun)
  1395.    ("^\\s *(defvar\\s +\\S +" nil decl)
  1396.    ("^\\s *(defconst\\s +\\S +" nil define)
  1397.    ("^\\s *(\\(provide\\|require\\|\\(auto\\)?load\\).*$" nil include)
  1398.    ("\\s *\\&\\(rest\\|optional\\)\\s *" nil keyword)
  1399.    ("(\\(let\\*?\\|cond\\|if\\|or\\|and\\|map\\(car\\|concat\\)\\|prog[n1*]?\\|while\\|lambda\\|function\\|set\\([qf]\\|car\\|cdr\\)?\\|nconc\\|eval-when-compile\\|condition-case\\|unwind-protect\\|catch\\|throw\\|error\\)[ \t\n]" 1 keyword)
  1400.    ))
  1401.  
  1402. (hilit-set-mode-patterns
  1403.  '(lisp-mode ilisp-mode)
  1404.  '(
  1405.    (";.*" nil comment)
  1406.    ("#|" "|#" comment)
  1407. ;;; This almost works...but I think I'll stick with the parser function 
  1408. ;;;("[^?]\\(\"\\(\"\\||\\([^\"]+\\|[\\]\\([\\][\\]\\)*\"\\)*\"\\)\\)" 1 string)
  1409.    (hilit-string-find ?\\ string)
  1410.  
  1411.    ;; this is waaaaaaaay too slow
  1412.    ;;   ("^\\s *(def\\(un\\|macro\\|advice\\|alias\\|method\\|subst\\)\\s \\S +[ \t\n]+\\(nil\\|(\\(([^()]*)\\|[^()]+\\)*)\\)" nil defun)
  1413.    ("^\\s *(def\\(un\\|macro\\|advice\\|subst\\|method\\)\\s " "\\()\\|nil\\)" defun)
  1414.  
  1415.    ("^\\s *(\\(def\\(var\\|type\\|parameter\\)\\|declare\\)\\s +\\S +" nil decl)
  1416.    ("^\\s *(def\\(const\\(ant\\)?\\|class\\|struct\\)\\s \\S +[ \t\n]+\\((\\(([^()]*)\\|[^()]+\\)*)\\)?" nil define)
  1417.    ("^\\s *(\\(provide\\|require\\|\\(auto\\)?load\\).*$" nil include)
  1418.    ("[ \t]\\&\\(key\\|rest\\|optional\\|aux\\)\\s *" nil keyword)
  1419.    ("(\\(let\\*?\\|locally\\|cond\\|if\\*?\\|or\\|and\\|map\\(car\\|c[ao]n\\)?\\|prog[nv1*]?\\|while\\|when\\|unless\\|do\\(\\*\\|list\\|times\\)\\|lambda\\|function\\|values\\|set\\([qf]\\|car\\|cdr\\)?\\|rplac[ad]\\|nconc\\|block\\|go\\|return\\(-from\\)?\\|[ec]?\\(type\\)?case\\|multiple-value-\\(bind\\|setq\\|list\\|call\\|prog1\\)\\|unwind-protect\\|handler-case\\|catch\\|throw\\|eval-when\\(-compile\\)?\\)[ \t\n]" 1 keyword)
  1420.    ))
  1421.  
  1422.  
  1423. (hilit-set-mode-patterns
  1424.  'plain-tex-mode
  1425.  '(("^%%.*$" nil comment)
  1426.    ("{\\\\em\\([^}]+\\)}" nil comment)
  1427.    ("\\(\\\\\\w+\\)" nil keyword)
  1428.    ("{\\\\bf\\([^}]+\\)}" nil keyword)
  1429.    ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" nil defun)
  1430.    ("\\\\\\(begin\\|end\\){\\([A-Za-z0-9\\*]+\\)}" nil defun)
  1431.    ;; ("[^\\\\]\\$\\([^$]*\\)\\$" nil string)
  1432.    ("\\$\\([^$]*\\)\\$" nil string)
  1433.    ))
  1434.  
  1435. ;; Reasonable extensions would include smarter parameter handling for such
  1436. ;; things as the .IX and .I macros, which alternate the handling of following
  1437. ;; arguments.
  1438.  
  1439. (hilit-set-mode-patterns
  1440.  'nroff-mode
  1441.  '(("^\\.[\\\][\\\"].*$" nil comment)
  1442.    ("^\\.so .*$" nil include)
  1443.    ("^\\.[ST]H.*$" nil defun)
  1444. ;;   ("^[^\\.].*\"[^\\\"]*\\(\\\\\\(.\\)[^\\\"]*\\)*\"" nil string)
  1445.    ("\"" "[^\\]\"" string)
  1446.    ("^\\.[A-Z12\\\\].*$" nil define)
  1447.    ("\\([\\\][^ ]*\\)" nil keyword)
  1448.    ("^\\.[A-Z].*$" nil keyword))
  1449.  nil 'case-insensitive)
  1450.  
  1451. (hilit-set-mode-patterns
  1452.  'texinfo-mode
  1453.  '(("^\\(@c\\|@comment\\)\\>.*$" nil comment)
  1454.    ("@\\(emph\\|strong\\|b\\|i\\){[^}]+}" nil comment)
  1455. ;; seems broken
  1456. ;; ("\\$[^$]*\\$" nil string)
  1457.    ("@\\(file\\|kbd\\|key\\){[^}]+}" nil string)
  1458.    ("^\\*.*$" nil defun)
  1459.    ("@\\(if\\w+\\|format\\|item\\)\\b.*$" nil defun)
  1460.    ("@end +[A-Za-z0-9]+[ \t]*$" nil defun)
  1461.    ("@\\(samp\\|code\\|var\\){[^}]+}" nil defun)
  1462.    ("@\\w+\\({[^}]+}\\)?" nil keyword)
  1463.    ))
  1464.  
  1465. (hilit-set-mode-patterns
  1466.  'dired-mode
  1467.  (append
  1468.   '(("^D.*$"  nil dired-deleted)
  1469.    ("^\\*.*$" nil dired-marked)
  1470.    ("^  d.*$" nil dired-directory)
  1471.    ("^  l.*$" nil dired-link)
  1472.    ("^  -.*#.*#$" nil dired-ignored))
  1473.   (list (cons
  1474.      (concat "^  .*\\("
  1475.          (mapconcat 'regexp-quote completion-ignored-extensions "\\|")
  1476.          "\\)$")
  1477.      '(nil dired-ignored)))))
  1478.  
  1479. (hilit-set-mode-patterns
  1480.  'jargon-mode
  1481.  '(("^:[^:]*:" nil jargon-entry)
  1482.    ("{[^}]*}+" nil jargon-xref)))
  1483.  
  1484. (hilit-set-mode-patterns
  1485.  'Info-mode
  1486.  '(("^\\* [^:]+:+" nil jargon-entry)
  1487.    ("\\*[Nn]ote\\b[^:]+:+" nil jargon-xref)
  1488.    ("  \\(Next\\|Prev\\|Up\\):" nil jargon-xref)
  1489.    ("- \\(Variable\\|Function\\|Macro\\|Command\\|Special Form\\|User Option\\):.*$"
  1490.     nil jargon-keyword)))    ; lisp manual
  1491.  
  1492. (hilit-set-mode-patterns
  1493.  'calendar-mode
  1494.  '(("[A-Z][a-z]+ [0-9]+" nil define)    ; month and year
  1495.    ("S  M Tu  W Th  F  S" nil label)    ; week days
  1496.    ("[0-9]+\\*" nil defun)        ; holidays
  1497.    ("[0-9]+\\+" nil comment)        ; diary days
  1498.    ))
  1499.  
  1500. (hilit-set-mode-patterns
  1501.  'pascal-mode
  1502.  '(("(\\*" "\\*)" comment)
  1503.    ("{" "}" comment)
  1504.    ;; Doesn't work when there are strings in comments....
  1505.    ;; ("'[^']*'" nil string)
  1506.    ("^#.*$" nil include)
  1507.    ("^[ \t]*\\(procedure\\|function\\)[ \t]+\\w+[^ \t(;]*" nil defun)
  1508.    ("\\<\\(program\\|begin\\|end\\)\\>" nil defun)
  1509.    ("\\<\\(external\\|forward\\)\\>" nil include)
  1510.    ("\\<\\(label\\|const\\|type\\|var\\)\\>" nil define)
  1511.    ("\\<\\(record\\|array\\|file\\)\\>" nil type)
  1512.    ("\\<\\(of\\|to\\|for\\|if\\|then\\|else\\|case\\|while\\|do\\|until\\|and\\|or\\|not\\|with\\|repeat\\)\\>" nil keyword)
  1513.    )
  1514.  nil 'case-insensitive)
  1515.  
  1516. (hilit-set-mode-patterns
  1517.  'icon-mode
  1518.  '(("\\(^\\|[^\\\\]\\)#.*$" nil comment)
  1519.    ("\\(^\\|[^\\\"]\\)\"\\([^\\\"]*\\(\\\\.[^\\\"]*\\)*_\n[ \t\n]*\\)*[^\\\"]*\\(\\\\.[^\\\"]*\\)*\"" nil string)
  1520.    ;; charsets: these do not work because of a conflict with strings
  1521.    ;;("'[^\\']*\\(\\\\.[^\\']*\\)*'" nil charset)
  1522.    ("^[ \t]*procedure[ \t]+[A-Za-z_0-9]+[ \t]*(" ")" defun)
  1523.    ("^[ \t]*record.*(" ")" include)
  1524.    ("^[ \t]*\\(\\$include.*$\\|\\(global\\|link\\|invocable\\)[ \t\n]+[A-Za-z_0-9]+\\([ \t\n]*,[ \t\n]*[A-Za-z_0-9]+\\)*\\)" nil include)
  1525.    ("^[ \t]*\\(local\\|static\\)[ \t\n]+[A-Za-z_0-9]+\\([ \t\n]*,[ \t\n]*[A-Za-z_0-9]+\\)*" nil decl)
  1526.    ("\\<\\(initial\\|end\\)\\>" nil glob-struct)
  1527.    ("^\\$[ \t]*\\(undef\\|define\\).*$" "[^\\]$" define)
  1528.    ("\\<\\(while\\|until\\|return\\|every\\|if\\|then\\|else\\|to\\|case\\|of\\|suspend\\|create\\|do\\|repeat\\|break\\)\\>" nil keyword)
  1529.    ))
  1530.  
  1531. ;; as you can see, I had two similar problems for Pascal and Icon. In
  1532. ;; Pascal, strings are delimited with ' and an embedded quote is doubled,
  1533. ;; thus string syntax would be extremely simple. However, if a string
  1534. ;; occurs within a comment, the following text is considered a string.
  1535. ;; 
  1536. ;; In Icon, strings are similar to C ones, but there are also charsets,
  1537. ;; delimited with simple quotes. I could not manage to use both regexps at
  1538. ;; the same time.
  1539. ;;
  1540. ;; The problem I have with my patterns for Icon is that this language
  1541. ;; has a string similar constant to the C one (but a string can be cut
  1542. ;; on several lines, if terminated by an underscore and continued with
  1543. ;; initial blanks, like this:
  1544. ;;         "This is a somewhat long _
  1545. ;;          string, written on three _
  1546. ;;          succesive lines"
  1547. ;; in order to insert a double quote in a string, you have to escape it
  1548. ;; with a \), but also a character set constant (named a charset), which
  1549. ;; uses single quotes instead of double ones. It would seem intuitive to
  1550. ;; highlight both constants in the same way.
  1551.  
  1552.  
  1553. (provide 'hilit19)
  1554.  
  1555. ;;; hilit19 ends here.
  1556. -- 
  1557.  
  1558.    Richard L. Goerwitz     ***      goer@midway.uchicago.edu
  1559.